package com.wangyi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

/**
 * 网易笔试第一题
 * 4
 * 1T 4T 7T 2B 5B 8B 9W
 * 1T 2T 3T 4T 5T 6T 7T
 * 1B 2W 3T 4B 5W 6T 8W
 * 2B 8B 5B 2B 6T 7W 4W
 */
public class test1 {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String N = in.nextLine();
            int n = Integer.valueOf(N);
            for(int i = 0; i<n; i++){
                String[] strs = in.nextLine().split(" ");
                System.out.println(check(strs) ? "YES" : "NO");
            }

        }
    }

    public static boolean check(String[] strs){
        HashMap<Character, ArrayList<Integer>> map = new HashMap<>();
        for(String str :strs){
            char c1 = str.charAt(0);
            char c2 = str.charAt(1);
            if(map.get(c2) == null){
                map.put(c2,new ArrayList<Integer>(){{add(c1 - '0');}});
            }else{
                map.get(c2).add(c1-'0');
            }
        }


        int[] chart = new int[10];
        int eCount = 0;

        for(Character c : map.keySet()){
            eCount++;
            map.get(c).forEach( e -> chart[e] = 1);
        }
        int bitCount = 0;
        for(int i = 1; i<=9; i++){
            if(chart[i] == 1) bitCount++;
        }

        return bitCount >=7 && eCount >2;
    }


}
